package com.vanzo.talkie;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.vanzo.talkie2.R;
import com.vanzo.util.LogUtil;

import java.util.ArrayList;
import java.util.List;

import cn.qqtheme.framework.picker.SinglePicker;

/**
 * Created by tisen on 2018/1/24.
 */

public class MicPicker {


    private static final String TAG = "MicPicker";
    private static List<String> sqValues;

    static {
        sqValues = new ArrayList<>();
        for (int i = 0; i <= 31; i++) {
            sqValues.add(i + "");
        }
    }


    private SinglePicker<String> picker;
    private Activity activity;
    private TextView textView;
    private String defaultString;
    private PickerSubmit pickerSubmit;

    public void setPickerSubmit(PickerSubmit pickerSubmit) {
        this.pickerSubmit = pickerSubmit;
    }

    public MicPicker(Activity activity, TextView textView, String defaultString) {
        this.activity = activity;
        this.textView = textView;
        this.textView.setText("MIC增益:"+defaultString);
        this.defaultString = defaultString;
        this.textView.setOnClickListener(textViewListener);
    }

    private View.OnClickListener textViewListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (picker == null) {
                picker = new SinglePicker<String>(activity, sqValues);
                picker.setTitleText("设置MIC级别");
                picker.setTopLineColor(Color.TRANSPARENT);
                picker.setTitleTextColor(activity.getResources().getColor(R.color.main_activity_background_color));
                picker.setSubmitTextColor(activity.getResources().getColor(R.color.wheel_pop_text_color_focus));
                picker.setTextColor(activity.getResources().getColor(R.color.wheel_pop_text_color_focus), activity.getResources().getColor(R.color.wheel_pop_text_color_normal));
            }
            picker.setAnimationStyle(R.style.Picker);
            picker.setOnItemPickListener(new SinglePicker.OnItemPickListener<String>() {
                @Override
                public void onItemPicked(int i, String s) {
                    textView.setText("MIC增益:" + s);
                    if (pickerSubmit != null) {
                        pickerSubmit.submit(i, s);
                    }
                }
            });
            picker.show();
            LogUtil.put(this, "index = " + sqValues.indexOf(defaultString) + "  " + defaultString, LogUtil.WARN);
            picker.setSelectedIndex(sqValues.indexOf(defaultString));
        }
    };

    interface PickerSubmit {
        void submit(int i, String s);
    }
}
